package com.sinosoft.zyxt.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.beans.factory.annotation.Value;

public class JdbcUtil {
		
//	@Value("${dataSource.url}")
//	private String URL;
//	@Value("${dataSource.driverClassName}")
//	private String DRIVERCLASSNAME;
//	@Value("${dataSource.username}")
//	private String USERNAME;
//	@Value("${dataSource.password}")
//	private String PASSWORD;

	 public static  Connection getConnection(){
		  Connection conn=null;
		  
		  try {
			String url="jdbc:oracle:thin://@192.168.100.154:1521/ggbak10";
			  String user="MBZY";
			  String password="MBZY";
			  
			  Class.forName("oracle.jdbc.driver.OracleDriver");//加载数据驱动
			  conn = DriverManager.getConnection(url, user, password);// 连接数据库
			  
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
			System.out.println("加载数据库驱动失败");
		}catch(Exception e){
			e.printStackTrace();
			System.out.println("连接数据库失败");
		}
		  return conn;
	  }
	  public static  void close(Connection conn, PreparedStatement ps, ResultSet rs){
		  try {
			if(rs!=null){
				  rs.close();
			  }
		} catch (SQLException e) {
			e.printStackTrace();
		}
		  
		  try {
				if(ps!=null){
					  ps.close();
				  }
			} catch (SQLException e) {
				e.printStackTrace();
			}
		  
		  try {
				if(conn!=null){
					  conn.close();
				  }
			} catch (SQLException e) {
				e.printStackTrace();
			}
		  
	  }
	
	
}
